from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)


class User(db.Model):
    user_id = db.Column(db.Integer, primary_key=True)
    user_name = db.Column(db.String(80), unique=True, nullable=False)
    password = db.Column(db.String(20),  nullable=False)
    user_level = db.Column(db.Integer,  nullable=False, default=1)
    enable_statu = db.Column(db.Boolean,  nullable=False, default=True)

    def __repr__(self):
        
        user_id = self.user_id,
        user_name = self.user_name,
        password = self.password,
        user_level = self.user_level,
        enable_statu = self.enable_statu
        
        return '{'+f"'user_id':{user_id[0]},'user_name':'{user_name[0]}' ,'password':'{password[0]}' ,'user_level':{user_level[0]} ,'enable_statu':{enable_statu}"+'}'

class Auth(db.Model):
    auth_id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.user_id'))
    user_name = db.Column(db.String(80), unique=True, nullable=False)
    login_time = db.Column(db.Integer, nullable=False)
    login_statu = db.Column(db.String(80),  nullable=False)
    
    def __repr__(self):
        return_info=dict(
            auth_id = self.auth_id,
            user_id = self.user_id,
            user_name = self.user_name,
            login_time = self.login_time,
            login_statu = self.login_statu
        )
        return return_info

db.create_all()
